package com.ywl.optional;

import com.ywl.entity.Author;

import java.util.Optional;
import java.util.function.Function;

/**
 * optional 数据转换
 * @author 24040
 * @name OptionalDemo01
 * @date 2022-08-23 16:51
 */
public class OptionalDemo05 {
    public static void main(String[] args) {
        test01();
    }


    /**
     * 数据转换
     */
    private static void test01() {
        Optional<Author> optionalAuthor = getOptionalAuthor();
        optionalAuthor.map(author -> author.getAge())
                        .ifPresent(age -> System.out.println(age));
    }

    public static Optional<Author> getOptionalAuthor() {
        Author author = new Author
                (1L, "蒙多", 33, "一个从菜刀中明悟哲理的祖安人", null);
        return Optional.ofNullable(author);
    }
}
